import { integralRecord_list } from '@/api/integralRecord'
import { searchTool } from '@/utils'
/* 积分纪录 */

const integralRecord = {
  state: {
    loading: false,
    tableList: [],
    listQuery: { start: 0, limit: 10, total: 0, current: 1},
    selectDept: {},
    scores: 0, //总积分
  },

  mutations: {
    SET_LIST_QUERY: (state, query) => {
        state.listQuery = query
    },
    SET_SELECT_DEPT: (state, dept) => {//设置当前选中的部门主键
        state.selectDept = dept
    },
    SET_TABLE_LIST: (state, list) => {
        state.tableList = list
    },
    SET_SCORES: (state, num) => {
        state.scores = num
    },
  },

  actions: {
    async findRecordListById({commit, state}, dept){
        commit('SET_SELECT_DEPT', dept)
        state.loading = true
        let parms = {dept_id : dept.id, company_id: localStorage.getItem("companyId") - 0, ...state.listQuery}
        let { data } = await integralRecord_list(parms)
        state.loading = false
        if(data.status == 100){
            let queryObj = {...state.listQuery, total: data.data.results}
            commit("SET_LIST_QUERY", queryObj)
            commit("SET_TABLE_LIST", data.data.rows)
            commit("SET_SCORES", data.data.scores)
        }
    },
    iRSearch({commit, state}){//搜索
        let keyWords = { key: 'searchDate', names: ['create_starttime', 'create_endtime']}
        let query = searchTool(state.listQuery, keyWords, examinehWords)
        commit("SET_LIST_QUERY", query)
    },
    iRSizeChange({commit, state}, limit) {
        let queryObj = {...state.listQuery, limit: limit}
        commit("SET_LIST_QUERY", queryObj)
    },
    iRCurrentChange({commit, state}, start) {
        let queryObj = {...state.listQuery, start: (start - 1) * state.listQuery.limit, current: start}
        commit("SET_LIST_QUERY", queryObj)
    },
    
  }
}

export default integralRecord
